package example.controller;

import example.atestEntity.Down;
import example.common.Result;
import example.dto.DidAndSidDTO;
import example.dto.ResponseDepartmentDTO;
import example.entity.SecondmentDistributeInfo;
import example.mapper.SecondmentDistributeInfoMapper;
import example.service.ISecondmentDistributeInfoService;
import example.vo.ResponseVO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/response")
public class ResponseController {

    @Resource
    private ISecondmentDistributeInfoService secondmentDistributeInfoService;

    @Resource
    private SecondmentDistributeInfoMapper secondmentDistributeInfoMapper;

    @PostMapping("/names")
    public Result getResponseDepartment(@RequestBody ResponseDepartmentDTO responseDTO) {
        return secondmentDistributeInfoService.getResponseDepartment(responseDTO);
    }

    @PostMapping("/change/state")
    public Result changeResponseState(@RequestBody DidAndSidDTO didAndSidDTO) {
        return secondmentDistributeInfoService.changeResponseState(didAndSidDTO);
    }

    @PostMapping("/get/state")
    public Result getResponseState(@RequestBody DidAndSidDTO didAndSidDTO) {
        return secondmentDistributeInfoService.getResponseState(didAndSidDTO);
    }
    @PostMapping("/pdf/name")
    public Result getPdfName(@RequestBody DidAndSidDTO didAndSidDTO) {
        SecondmentDistributeInfo secondmentDistributeInfo = new SecondmentDistributeInfo();
        secondmentDistributeInfo.setDepartmentId(didAndSidDTO.getDepartmentId());
        secondmentDistributeInfo.setSecondmentId(didAndSidDTO.getSecondmentId());
        SecondmentDistributeInfo resFile = secondmentDistributeInfoMapper.getResFile(secondmentDistributeInfo);
        String responseFileName = resFile.getResponseFileName();
        return  Result.ok(responseFileName);
    }
    @GetMapping("/file")
    public void dowRes(@RequestParam Long departmentId, @RequestParam Long secondmentId, HttpServletResponse response) {
        secondmentDistributeInfoService.dowRes(departmentId, secondmentId, response);
    }
}
